using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using GonzalesCore.CoreElements;
using GonzalesCore.CoreManagers;

using Kypris2.CoreElements;

using Jamila2.Tools;

public partial class GonzalesHeader : System.Web.UI.Page
{
    #region Variables
    protected PrivateLoginSession CurrentPrivateSession = null;    

    protected string LogoutConfirmText = "";

    protected string AssistantClaimantOf
    {
        get
        {
            return ViewState["AssistantClaimantOf"].ToString();
        }

        set
        {
            ViewState["AssistantClaimantOf"] = value;
        }
    }

    protected string AssistantReviewerOf
    {
        get
        {
            return ViewState["AssistantReviewerOf"].ToString();
        }

        set
        {
            ViewState["AssistantReviewerOf"] = value;
        }
    }
    #endregion

    #region Events

    #region Page_Load
    protected void Page_Load(object sender, EventArgs e)
    {
        this.SessionCheck();    // first thing to do for every page

        if (Request.QueryString["LOGOUT"] != null && Request.QueryString["LOGOUT"].CompareTo("1") == 0)
        {
            Session.Abandon();
            Response.Redirect("default.aspx");
        }

        if (!IsPostBack)
        {
            this.SwitchLanguage();
            this.PageComponentSetup();
        }

        this.PolicySetting();
    }
    #endregion

    #endregion

    #region Customized Methods

    #region SessionCheck
    public void SessionCheck()
    {
        if (Session[GonzalesCommonNamingConvention.CurrentPrivateSession] != null)
        {
            this.CurrentPrivateSession = (PrivateLoginSession)Session[GonzalesCommonNamingConvention.CurrentPrivateSession];
        }
        else
        {
            Response.Redirect(GonzalesErrorPageRedirect.SessionError);
        }
    }
    #endregion

    #region PageComponentSetup
    protected void PageComponentSetup()
    { 
        // setup js
        this.HyperLink_Logout.Attributes["onclick"] = "return confirm('" + this.LogoutConfirmText + "');";
        this.HyperLink_Main.Attributes["onclick"] = "HighLight('HyperLink_Main');";
        this.HyperLink_Administrator.Attributes["onclick"] = "HighLight('HyperLink_Administrator');";
        this.HyperLink_Utilities.Attributes["onclick"] = "HighLight('HyperLink_Utilities');";
        this.HyperLink_Options.Attributes["onclick"] = "HighLight('HyperLink_Options');";
        this.HyperLink_Help.Attributes["onclick"] = "HighLight('HyperLink_Help');";
        this.HyperLink_MyClaims.Attributes["onclick"] = "HighLight('HyperLink_MyClaims');";
        this.HyperLink_NewClaim.Attributes["onclick"] = "HighLight('HyperLink_NewClaim');";
        this.HyperLink_MyDrafts.Attributes["onclick"] = "HighLight('HyperLink_MyDrafts');";
        this.HyperLink_SubmittedClaims.Attributes["onclick"] = "HighLight('HyperLink_SubmittedClaims');";
        this.HyperLink_VerifiedClaims.Attributes["onclick"] = "HighLight('HyperLink_VerifiedClaims');";
        this.HyperLink_AuthorizedClaims.Attributes["onclick"] = "HighLight('HyperLink_AuthorizedClaims');";
        this.HyperLink_ApprovedClaims.Attributes["onclick"] = "HighLight('HyperLink_ApprovedClaims');";

    }
    #endregion    

    #region SwitchLanguage
    protected void SwitchLanguage()
    {
        MultiLingualFactory CurLanguageFactory = null;        
        CurLanguageFactory = MultiLingualEngine.GetMultiLingualFactory(this, this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage.InternalID);

        this.LogoutConfirmText = CurLanguageFactory.DisplayValue("LogoutConfirmation");        

        this.HyperLink_Main.Text = CurLanguageFactory.DisplayValue("OptionMain");
        this.HyperLink_Options.Text = CurLanguageFactory.DisplayValue("OptionOptions");
        this.HyperLink_Administrator.Text = CurLanguageFactory.DisplayValue("OptionAdministrator");
        this.HyperLink_Utilities.Text = CurLanguageFactory.DisplayValue("OptionUtilities");
        this.HyperLink_Help.Text = CurLanguageFactory.DisplayValue("OptionHelp");
        this.HyperLink_Logout.Text = CurLanguageFactory.DisplayValue("OptionLogout");

        this.HyperLink_NewClaim.Text = CurLanguageFactory.DisplayValue("LinkNewClaim");
        this.HyperLink_MyClaims.Text = CurLanguageFactory.DisplayValue("LinkMyClaims");
        this.HyperLink_MyDrafts.Text = CurLanguageFactory.DisplayValue("LinkMyDrafts");
        this.HyperLink_SubmittedClaims.Text = CurLanguageFactory.DisplayValue("LinkSubmittedClaims");        
        this.HyperLink_ApprovedClaims.Text = CurLanguageFactory.DisplayValue("LinkApprovedClaim");
        this.HyperLink_AuthorizedClaims.Text = CurLanguageFactory.DisplayValue("LinkAuthorizedClaims");
        this.HyperLink_VerifiedClaims.Text = CurLanguageFactory.DisplayValue("LinkVerifiededClaims");
        this.AssistantClaimantOf = CurLanguageFactory.DisplayValue("ItemAssistantClaimantOf");
        this.AssistantReviewerOf = CurLanguageFactory.DisplayValue("ItemAssistantReviewerOf");

        if (this.CurrentPrivateSession.CurrentLoggedOnUser.AppRoute == ApprovingRoute.Normal || this.CurrentPrivateSession.CurrentLoggedOnUser.AppRoute == ApprovingRoute.MultiLevel)
        {
            if (this.CurrentPrivateSession.CurrentLoggedOnUser.PersonnelReportTo == null && !this.CurrentPrivateSession.CurrentLoggedOnUser.NoApprover)
            {
                this.HyperLink_NewClaim.Attributes["onclick"] = "alert('" + CurLanguageFactory.DisplayValue("NewClaimError") + "'); return false;";
                this.HyperLink_NewClaim.NavigateUrl = "#";                
            }
        }

    }
    #endregion

    #region PolicySetting
    public void PolicySetting()
    {
        // claimant menu
        this.Table_ClaimantMenu.Visible = !this.CurrentPrivateSession.ShadowMode;
        
        // approver menu
        this.Table_ApproverMenu.Visible = (this.CurrentPrivateSession.CurrentLoggedOnUser.IsApprover || this.CurrentPrivateSession.CurrentLoggedOnUser.IsAuthorizationPersonnel);
        this.Menu_SubmittedClaims.Visible = this.CurrentPrivateSession.CurrentLoggedOnUser.IsApprover;
        this.Menu_ApprovedClaims.Visible = this.CurrentPrivateSession.CurrentLoggedOnUser.IsAuthorizationPersonnel;

        // finance menu
        this.Table_FinanceMenu.Visible = (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceAdmin || this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceApprover);
        this.Menu_AuthorizedClaims.Visible = this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceAdmin;
        this.Menu_VerifiedClaims.Visible = this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceApprover;

        // admin menu
        this.Table_GeneralMenu.Rows[0].Cells[2].Visible = this.CurrentPrivateSession.CurrentLoggedOnUser.IsAdmin && !this.CurrentPrivateSession.ShadowMode;
        this.Table_GeneralMenu.Rows[0].Cells[3].Visible = this.CurrentPrivateSession.CurrentLoggedOnUser.IsAdmin && !this.CurrentPrivateSession.ShadowMode;

        // shadow mode have the final say

        // check on behalf mode
        if (this.CurrentPrivateSession.ShadowMode)
        {
            if (this.CurrentPrivateSession.CurrentLoggedOnUser.OnBehalfBy != null &&
                this.CurrentPrivateSession.CurrentLoggedOnUser.OnBehalfBy.InternalID.CompareTo(this.CurrentPrivateSession.ShadowUser.InternalID) == 0)
            {
                this.Table_ApproverMenu.Visible = this.Table_FinanceMenu.Visible = this.GM_Options.Visible = !this.CurrentPrivateSession.ShadowMode;

                // normal on behalf
                this.Table_ClaimantMenu.Visible = true;
                LabelValue_LoginOnBehalf.Visible = true;
                Label_LoginOnBehalf.Visible = true;
                Label_LoginOnBehalf.Text = this.AssistantClaimantOf;
                LabelValue_LoginOnBehalf.Text = this.CurrentPrivateSession.CurrentLoggedOnUser.DisplayName;

            }

            if (this.CurrentPrivateSession.CurrentLoggedOnUser.ReviewOnBehalfBy != null &&
                this.CurrentPrivateSession.CurrentLoggedOnUser.ReviewOnBehalfBy.InternalID.CompareTo(this.CurrentPrivateSession.ShadowUser.InternalID) == 0)
            {
                // review on behalf
                this.Table_ApproverMenu.Visible = true;
                this.Menu_SubmittedClaims.Visible = true;

               // this.Menu_ApprovedClaims.Visible = true;
                //if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsAuthorizationPersonnel)
                //    this.Menu_ApprovedClaims.VerticalAlign = true;

                //if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceAdmin)
                //    this.Menu_VerifiedClaims.Visible = true;

                //if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceApprover)
                //    this.Menu_AuthorizedClaims.VerticalAlign = true;

                LabelValue_LoginOnBehalf.Visible = true;
                Label_LoginOnBehalf.Visible = true;
                Label_LoginOnBehalf.Text = this.AssistantReviewerOf;
                LabelValue_LoginOnBehalf.Text = this.CurrentPrivateSession.CurrentLoggedOnUser.DisplayName;
            }
        }

    }
    #endregion

    #endregion
}
